// pages/Personal/balrecord/balrecord.js
var ikz = require('../../Common/tools.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    balance_info: '',//余额记录信息
    page: 1,//页数
    limit: 10,//每页条数
    prodis: 'none',//底部提示是否显示
  },
  

  goback:function(){
    wx.navigateBack()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    ikz.over(this);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var page = 1;
    var limit = that.data.limit;
    var path = 'Percenter/myBalance';
    var data = {
      page: page,
      limit: limit,
    }
    ikz.request(path, data, true, (res) => {
      console.log(res);
      if (res.data.status == 'success') {
        that.setData({
          balance_info: res.data.balance_info,
          page: page,
        });
        ikz.hide(that);
      } else {
        wx.showModal({
          title: '提示',
          content: '服务器繁忙，请稍后重试！',
          showCancel: false
        })
      }

    });
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载中',
    });
    var that = this;
    var page = that.data.page + 1;
    var limit = that.data.limit;
    var old_balance_info = that.data.balance_info;
    var path = 'Percenter/myBalance';
    var data = {
      page: page,
      limit: limit,
    }

    ikz.request(path, data, true, (res) => {
      console.log(res);
      console.log(6767);
      if (res.data.status == 'success') {
        var new_info = res.data.balance_info;
        if (new_info.length) {
          var new_balance_info = old_balance_info.concat(new_info);
          var prodis = 'none';
        } else {
          var new_balance_info = old_balance_info;
          var prodis = 'block';
        }
        that.setData({
          balance_info: new_balance_info,
          page: page,
          prodis: prodis,
        })
      } else {
        wx.showModal({
          title: '提示',
          content: '服务器繁忙，请稍后重试！',
          showCancel: false
        })
      }

    });
    wx.hideLoading();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})